<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp"%>

<!DOCTYPE html>
<html>
<head>
    <title><spring:message code="message.lable.drugqualityspecSeeStd"/></title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp"%>
    <!--[if lt IE 9]>
        <script src="${ctx}/lib/js/html5shiv.min.js"></script>
        <script src="${ctx}/lib/js/respond.min.js"></script>
    <![endif]-->
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
                            
    <section class="content-header">
        <h1>配送企业采购情况</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i><spring:message code="message.lable.first"/></a></li>
                <li><a href="#">监管系统</a></li>
                <li><a href="#">配送企业采购情况</a></li>
        </ol>
    </section>
        
    <section class="content">
    <div class="box box-success">
    	<div class="box-body">
				<div class="input">
                    <div class="textalign1">月度<spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput">
                    		<table style="width:100%">
                    			<tr>
                    				<td style="width:50%">
                    					<input id="startMon2" name="startMon2" class="textinput" type="text" readonly placeholder="月度"  data-date-fmt="yyyy-MM"  data-provide="datepicker"/>
                    				</td>
                    			</tr>
                    		</table>
                    </div>
                     <div class="textalign" >
                         <button id="selectSpec1" type="button" onclick="search2();" class="btn btn-success btn-sm"><spring:message code="message.button.seachSpacing"/></button>
                    </div>
                </div>
            </div>
            </div>
    	<div class="box box-success">
    		<div class="box-header with-border">
    			<h3 class="box-title" id="chartTitle"><fmt:formatDate value='${lastMonth}' pattern='yyyy年MM月' />企业采购金额前十名</h3>
                <div class="box-tools pull-right">
                    <button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
                </div><!-- /.box-tools -->
            </div>
            <div class="box-body mchart">
                <div id="mChart" style="height: 400px; width:98%; padding: 8px;"></div>
            </div>
        </div>
        <div class=" box box-success">
            <div class="box-body">
             <form  id="form" method="post" action='${ctx}/anaDruginfo/exportExcelWithCompMon.html'>
                <div class="input">
                	
                    <div class="textalign1">月度<spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput">
                    		<table style="width:100%">
                    			<tr>
                    				<td style="width:50%">
                    					<input id="startMonth" name="startMonth" class="textinput" type="text" readonly placeholder="开始月份"  data-date-fmt="yyyy-MM"  onfocus="WdatePicker({dateFmt:'yyyy-MM',maxDate:'#F{$dp.$D(\'endMonth\')}'})"/>
                    				</td>
                    				<td>&nbsp;-&nbsp;</td>
                    				<td style="width:50%">
                    					<input id="endMonth" name="endMonth" class="textinput" type="text" readonly placeholder="结束月份"  data-date-fmt="yyyy-MM"  onfocus="WdatePicker({dateFmt:'yyyy-MM',minDate:'#F{$dp.$D(\'startMonth\')}'})"/>
                    				</td>
                    			</tr>
                    		</table>
                    </div>
                    
                    <div class="textalign">配送企业<spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput">
                         <input type="text" class="textinput" id="delCompName" name="delCompName" placeholder="配送企业/<spring:message code="message.listForm.pinYinMa"/>" maxlength="100"  /> 
                    </div>
                    
                     <div class="textalign" >
                         <button id="selectSpec" type="button" onclick="search();" class="btn btn-success btn-sm"><spring:message code="message.button.seachSpacing"/></button>
                    </div>
                    <div class="textalign1" >
						 <button id="exportExcel" type="button"  class="btn btn-success btn-sm">导 出</button>
                    </div>
                </div>
            </form>
            </div>
          </div>
        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>
        <%-- <div class=" box box-warning bottongroup">
			<button type="button" onclick="toYearAnaByComp();" class="btn btn-primary btn-sm">年度记录</button>
			<button type="button" onclick="toSeaAnaByComp ();" class="btn btn-primary btn-sm">季度记录</button>
        </div>--%>
    </section>
      <%@ include file="/WEB-INF/component/commonJS.jsp"%>
    <script type="text/javascript">
        $(function () {
        	//绑定回车
            $('#startMon2').bind('keydown', function(event) {
                if (event.keyCode == "13") {        //13 位电脑上回车键的位置代码
                    $('#selectSpec1').click();
                }
            }); 
        	
        	$('#form :input').bind('keydown', function(event) {if (event.keyCode == "13") {search();}});
        	
        	 $("#delCompName").focus();//加载页面光标在第一个查询框内
        	
            $("#gridlist").jqGrid({
                url: "${ctx}/anaDruginfo/getMonthAnaByComp.html?date=${date}",
                mtype: "post",
                datatype: "json",
                autowidth: true,
                height: 310,
                colNames: [
					'操作',
					'月度',
                    '配送企业',
                    '采购总金额(万元)',
                  //  '西药采购金额(万元)', 
                  // 	'中药采购金额(万元)',
                   	'配送金额(万元)',
                   	'入库金额(万元)',
                    '中药采购率',
                    '配送率',
					'入库率',
					'退货率'
                ],
                colModel: [
					{name:'oper',index:'formName', width:140, align:"center", sortable:false,formatter:function(val,option,rowdata){
						var str = "<a href='javascript:void(0)' onclick=\"xgTz('"+rowdata.del_comp_code+"','"+rowdata.date+"','"+rowdata.del_comp_name+"','"+rowdata.total_amount+"','"+rowdata.del_amount+"','"+rowdata.recp_amount+"','2')\"  style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -40px -80px' class='opIcon' title='采购药品'></a>";
						str += "<a href='javascript:void(0)' onclick=\"xgTz('"+rowdata.del_comp_code+"','"+rowdata.date+"','"+rowdata.del_comp_name+"','"+rowdata.total_amount+"','"+rowdata.del_amount+"','"+rowdata.recp_amount+"','1')\"  style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -20px -120px' class='opIcon' title='采购医院'></a>";
						if(!"${areaHidden}"){
							str += "<a href='javascript:void(0)' onclick=\"xgTz('"+rowdata.del_comp_code+"','"+rowdata.date+"','"+rowdata.del_comp_name+"','"+rowdata.total_amount+"','"+rowdata.del_amount+"','"+rowdata.recp_amount+"','3')\"  style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -20px -100px' class='opIcon' title='采购地区'></a>";
						}
						str += "<a href='javascript:void(0)' onclick=\"xgTz('"+rowdata.del_comp_code+"','"+rowdata.date+"','"+rowdata.del_comp_name+"','"+rowdata.total_amount+"','"+rowdata.del_amount+"','"+rowdata.recp_amount+"','4')\"  style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -40px -120px' class='opIcon' title='采购生产企业'></a>";
						return str;
					}},
					{ name: 'date', width: 150, align:"center", sortable: false},
                    { name: 'del_comp_name', width: 220, align:"center", sortable: false},
                    { name: 'total_amount', width: 120, align:"center", sortable: false},
                  //  { name: 'western_amount', width: 120, align:"center", sortable: false},
                  //  { name: 'eastern_amount', width: 120, align:"center", sortable: false},
                    { name: 'del_amount', width: 100, align:"center", sortable: false},
                    { name: 'recp_amount', width: 100, align:"center", sortable: false},
                    { name: 'eastern_ratio', width: 90, align:"center",hidden:true, sortable: false},
                    { name: 'del_ratio', width: 90, align:"center", sortable: false},
                    { name: 'recp_ratio', width: 90, align:"center", sortable: false},
					{ name: 'ret_ratio', width: 90,hidden:true, align:"center", sortable: false}
                ],
                rowNum: 20,
                rowList: [10, 20, 50,100],
                rownumbers: true,
                pager: "#gridpage",
                multiselect: false, 
                viewrecords: true,
                caption: "配送企业月度统计列表",
                gridComplete:function(){
                    autoRNWidth("gridlist");
                },
                jsonReader: {
                	 repeatitems: false,
                    id: "qualitySpecId"
                }
            });
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            $(window).trigger("resize");
			
			$('#exportExcel').bind('click',function(){
            	$('#form').submit();
            });
			loadChart("<fmt:formatDate value='${lastMonth}' pattern='yyyy-MM' />");
        });
        function search(page) {
        	
        	 var startMonth = $("#startMonth").val();
             var endMonth = $("#endMonth").val();
              if(endMonth.length > 0 && startMonth.length == 0 ) {
                  $("#startMonth").trigger("focus");
                  $.alert("请选择开始月份！", "warn");
                  return;
              }
			
            var data =formatForm("form");
            $("#gridlist").jqGrid('setGridParam',{  
                datatype:'json',
                postData:data,
                page : (page || 1)
            }).trigger("reloadGrid"); //重新载入  
        }
        
        
        function search2() {			
			var startMon2 = $.trim($("#startMon2").val());
			if(startMon2.length == 0) {
				return;
			}
			
			if(startMon2.length > 0) {
				$("#chartTitle").text(startMon2.replace("-","年")+"企业采购金额前十名");
			}
			loadChart(startMon2)
		}
		function loadChart(startMon) {
			
			$.ajax({
                       type: "POST",
                       url: "${ctx}/anaDruginfo/getChartMonthAnaByComp.html",
                       data:{
                            startMon:startMon
                       },
                       dataType:"json",
                       success: function(result){
                           if(result.success){
                        	   var option = {
                           		    tooltip : {
                           		        trigger: 'axis',
                           		        axisPointer : {            // 坐标轴指示器，坐标轴触发有效
                           		            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                           		        }
                           		    },
                           		    legend: {
                           		        data:[]
                           		    },
                           		    toolbox: {
                           		        show : true,
                           		        feature : {
                           		            mark : {show: false},
                           		            dataView : {show: false, readOnly: false},
                           		            magicType : {show: false, type: ['line', 'bar', 'stack', 'tiled']},
                           		            restore : {show: false},
                           		            saveAsImage : {show: false}
                           		        }
                           		    },
                           		    calculable : true,
                           		    xAxis : [
                           		        {
                           		            type : 'value',
                           		            name : '总金额(万元)'
                           		        }
                           		    ],
									  grid: { // 控制图的大小，调整下面这些值就可以，
										 x: 200,
									 },
                           		    yAxis : [
                           		        {
                           		            type : 'category',
                           		            data :  eval(result.conditions.yComp)
                           		        }
                           		    ],
                           		    series : [
                           		        {	/* itemStyle: {
	                        		            normal: {
	                         		               color: function(params) {
	                         	                        var colorList = [
	                         	                          '#b5c334','#fcce10','#e87c25','#53a5ac','#fe8463',
	                         	                           '#ecbc7c','#fad860','#4396c6','#9bca63','#da4a37'
	                         	                        ];
	                         	                        return colorList[params.dataIndex]
	                         	                    },
	                         		            }
                         		        	}, */
                           		        	barGap:30, 
                           		            name:'总金额(万元)',
                           		            type:'bar',
                           		            data:eval(result.conditions.total)
                           		        }
                           		    ]
                           		};
                        		var myChart = echarts.init(document.getElementById('mChart'));
                                myChart.setOption(option);
                           }
					   }
              });
			
		}
        
        function toYearAnaByComp(){
        	window.location.href="${ctx}/anaDruginfo/toYearAnaByComp.html"; 
        }
        
        function toSeaAnaByComp(){
        	window.location.href="${ctx}/anaDruginfo/toSeaAnaByComp.html"; 
        }
		
		function xgDrug(compCode) {
			window.location.href="${ctx}/anaDruginfo/toAnaDelByDrugWithMon.html?compCode="+compCode; 
		}
		
		
		function xgTz(delCompCode,date,delCompName,total,del,recp,type) {
			//type 1医疗机构2药品3地区4生产企业
			window.location.href="${ctx}/anaDruginfo/toAnaByCompTz.html?dateType=mon&delCompCode="+delCompCode+"&date="+date+"&delCompName="+delCompName+"&total="+total+"&del="+del+"&recp="+recp+"&type="+type; 
		}
    </script>
</body>
</html> 
                          
                  
                  